package com.example.blog.service.impl;

import com.example.blog.dao.MessageMapper;
import com.example.blog.pojo.Message;
import com.example.blog.service.MessageService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @date: 2020/9/7
 * @author: 东北宋小宝
 * @version: 1.0
 * @Description:
 */
@Service
public class MessageServiceImpl implements MessageService {
    @Resource
    private MessageMapper messageMapper;
    @Value("${blogpage.userAvatar}")
    private String avatar;

    /***
     * 保存留言实体评论
     * @param message
     */
    @Override
    public void saveMessage(Message message) {
        if (!message.isAdminMessage()) {
            message.setAvatar(avatar);
        }
        message.setCreatTime(new Date());
        messageMapper.insertMessage(message);
    }

    /***
     * 获取所有评论
     * @return
     */
    @Override
    public List<Message> getAllMessage() {

        List<Message> allMessage = messageMapper.getAllMessage(null);
        return allMessage;
    }
}
